package com.iplay.实战java高并发程序设计.chapter2;

/**
 * @author dangwu
 * @since 2021/10/13 7:26 下午
 */
public class ThreadGroupName implements Runnable{

    @Override
    public void run() {
        String groupAndName = Thread.currentThread().getThreadGroup().getName()+"-"+Thread.currentThread().getName();
        while (true){
            System.out.println("i am "+ groupAndName);
            try {
                Thread.sleep(3000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }

    public static void main(String[] args) {
//        Thread t = new Thread("high");
//        System.out.println(t.getName());
        ThreadGroup tg = new ThreadGroup("goooo");
        Thread t1 = new Thread(tg,new ThreadGroupName(),"t1");
        Thread t2 = new Thread(tg,new ThreadGroupName(),"t2");
        t1.start();
        t2.start();
        System.out.println(tg.activeCount());
        tg.list();

    }
}
